package domainLogic;

import java.io.IOException;

/**
 * @author  jungmins
 */
public class BiddingService 
{
	/**
	 * @uml.property  name="instance"
	 * @uml.associationEnd  
	 */
	private static BiddingService instance = new BiddingService();
	
	/**
	 * @return
	 * @uml.property  name="instance"
	 */
	public static BiddingService getInstance()
	{
		return instance;
	}
		
	public BiddingService() {  }
	
	public synchronized boolean createNewBid(domainLogic.Bid newBid, javax.servlet.jsp.JspWriter out) throws IOException
	{
		long startTime = System.currentTimeMillis();
		int itemId = newBid.getItemId();
	
		ItemView it = dataGateway.ItemViewTable.getInstance().getItem(itemId);
		
		if(it.validateBid(newBid, out) == false)
			return false;

		if(dataGateway.BidTable.getInstance().insertBid(newBid) == false)
			return false;
	
		it.updateEndDate(newBid);
		System.out.println("createNewBid: "+(System.currentTimeMillis()-startTime));
		return true;
	}
}
